package com.yike.user.service.impl;

import com.yike.user.entity.AgentWithdrawalRecord;
import com.yike.user.mapper.AgentWithdrawalRecordMapper;
import com.yike.user.service.AgentWithdrawalRecordService;
import com.yike.user.param.AgentWithdrawalRecordPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 代理商提现记录表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-23
 */
@Slf4j
@Service
public class AgentWithdrawalRecordServiceImpl extends BaseServiceImpl<AgentWithdrawalRecordMapper, AgentWithdrawalRecord> implements AgentWithdrawalRecordService {

    @Autowired
    private AgentWithdrawalRecordMapper agentWithdrawalRecordMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAgentWithdrawalRecord(AgentWithdrawalRecord agentWithdrawalRecord) throws Exception {
        return super.save(agentWithdrawalRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAgentWithdrawalRecord(AgentWithdrawalRecord agentWithdrawalRecord) throws Exception {
        return super.updateById(agentWithdrawalRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAgentWithdrawalRecord(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AgentWithdrawalRecord> getAgentWithdrawalRecordPageList(AgentWithdrawalRecordPageParam agentWithdrawalRecordPageParam) throws Exception {
        Page<AgentWithdrawalRecord> page = new PageInfo<>(agentWithdrawalRecordPageParam, OrderItem.desc(getLambdaColumn(AgentWithdrawalRecord::getCreateTime)));
        LambdaQueryWrapper<AgentWithdrawalRecord> wrapper = new LambdaQueryWrapper<>();
        IPage<AgentWithdrawalRecord> iPage = agentWithdrawalRecordMapper.selectPage(page, wrapper);
        return new Paging<AgentWithdrawalRecord>(iPage);
    }

}
